//
//  ZRCellBottom.swift
//  Sina
//
//  Created by 张锐 on 16/3/2.
//  Copyright © 2016年 zhangr. All rights reserved.
//

import UIKit

class ZRCellBottom: UIView {
    
    var statusViewModel : ZRHomeCellViewModel?{
    
        didSet{
        
            retweetButton.setTitle(statusViewModel?.reposts_Str, forState: UIControlState.Normal)
            
            commentButton.setTitle(statusViewModel?.comments_Str, forState: UIControlState.Normal)

            goodButton.setTitle(statusViewModel?.attitudes_Str, forState: UIControlState.Normal)
        
        }

    }

    //重写构造函数
    
    override init(frame: CGRect) {
       
        super.init(frame: frame)
        
//        backgroundColor = UIColor.orangeColor()
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //私有添加控件设置约束
    
    private func setupUI(){
    
        addSubview(retweetButton)
        
        addSubview(commentButton)
        
        addSubview(goodButton)
        
        let leftLine = getline()
        
        let rightLine = getline()

        addSubview(leftLine)
        
        addSubview(rightLine)
        
        //添加约束
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(commentButton.snp_width)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            make.left.equalTo(retweetButton.snp_right)
            
            make.right.equalTo(goodButton.snp_left)
            
        }
        goodButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            make.right.equalTo(self.snp_right)
            
            make.width.equalTo(commentButton.snp_width)
            
        }
        
        leftLine.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            make.centerX.equalTo(retweetButton.snp_right)
            
            make.centerY.equalTo(self.snp_centerY)
        }
        
        rightLine.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            make.centerX.equalTo(goodButton.snp_left)
            
            make.centerY.equalTo(self.snp_centerY)
        }
    
    
    }
    
    //懒加载控件
    
    private lazy var retweetButton : UIButton = {
    
        let retweetButton = UIButton()
        
        retweetButton.setTitle("转发", forState: UIControlState.Normal)
        
        retweetButton.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        retweetButton.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        retweetButton.setTitleColor(UIColor(white: 237/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return retweetButton
    
    }()
    
    private lazy var commentButton : UIButton = {
    
        let commentButton = UIButton()
        
        commentButton.setTitle("评论", forState: UIControlState.Normal)
        
        commentButton.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        commentButton.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        commentButton.setTitleColor(UIColor(white: 237/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return commentButton
    
    }()
    
    private lazy var  goodButton : UIButton = {
    
        let goodButton = UIButton()
        
        goodButton.setTitle("赞", forState: UIControlState.Normal)
        
        goodButton.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        goodButton.setImage(UIImage(named: "timeline_icon_unlike"), forState: UIControlState.Normal)
        
        goodButton.setTitleColor(UIColor(white: 237/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return goodButton
    
    }()
    
    private func getline ()->(UIImageView){
    
        let line = UIImageView()
        
        line.image = UIImage(named: "timeline_card_bottom_line_highlighted")
        
        return line
    }

}
